<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Cookie;

class Index extends Controller
{
    public function index()
    {
      $url="http://".$_SERVER ['HTTP_HOST'].$_SERVER['PHP_SELF'];
      preg_match("#http://(.*?)\.#i",$url,$match);
      // var_dump($match);exit;
      $prefix = DB('area')->field('areaid,areaname')->where('pinyin','$match[1]')->find();
      Cookie::set('city',$prefix['areaname']);
      // $citys = Cookie::get('city');
      // dump($citys);
      // $area = DB('news')->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(15)->select();
      $new = DB('cat')->where('parentid',0)->select();
      //第一个
      $cat = DB('cat')->where('id',1)->select();
      $type = DB('cat')->where('parentid',1)->select();
      $new1=DB('news')->field('title,id,pic')->where(['superior_id'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(15)->select();
      $new2=DB('news')->field('title,id,pic')->where(['superior_id'=>1,'information'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
      $new3=DB('news')->field('title,id,pic')->where(['superior_id'=>1,'information'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
      $new4=DB('news')->field('title,id,pic')->where(['superior_id'=>1,'recommended'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
      $new5=DB('news')->field('title,id,pic')->where(['superior_id'=>1,'recommended'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
        $this->assign('type',$type);
        $this->assign('new',$new);
        $this->assign('cat',$cat);
        $this->assign('new1',$new1);
        $this->assign('new2',$new2);
        $this->assign('new3',$new3);
        $this->assign('new4',$new4);
        $this->assign('new5',$new5);
      //第二个
      $cat2 = DB('cat')->where('id',2)->select();
      $type2 = DB('cat')->where('parentid',2)->select();
      $new11=DB('news')->field('title,id,pic')->where(['superior_id'=>2])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(15)->select();
      $new22=DB('news')->field('title,id,pic')->where(['superior_id'=>2,'information'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
      $new33=DB('news')->field('title,id,pic')->where(['superior_id'=>2,'information'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
      $new44=DB('news')->field('title,id,pic')->where(['superior_id'=>2,'recommended'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
      $new55=DB('news')->field('title,id,pic')->where(['superior_id'=>2,'recommended'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
        $this->assign('cat2',$cat2);
        $this->assign('type2',$type2);
        $this->assign('new11',$new11);
        $this->assign('new22',$new22);
        $this->assign('new33',$new33);
        $this->assign('new44',$new44);
        $this->assign('new55',$new55);
      //第三个
      $type3 = DB('cat')->where('parentid',3)->select();
      $cat3 = DB('cat')->where('id',3)->select();
      $san1=DB('news')->field('title,id,pic')->where(['superior_id'=>3])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(15)->select();
      $san2=DB('news')->field('title,id,pic')->where(['superior_id'=>3,'information'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
      $san3=DB('news')->field('title,id,pic')->where(['superior_id'=>3,'information'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
      $san4=DB('news')->field('title,id,pic')->where(['superior_id'=>3,'recommended'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
      $san5=DB('news')->field('title,id,pic')->where(['superior_id'=>3,'recommended'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
        // dump($new1);die;
        $this->assign('type3',$type3);
        $this->assign('cat3',$cat3);
        $this->assign('san1',$san1);
        $this->assign('san2',$san2);
        $this->assign('san3',$san3);
        $this->assign('san4',$san4);
        $this->assign('san5',$san5);
        $this->assign('type',$type);
        //第四个
      $type4= DB('cat')->where('parentid',4)->select();
      $cat4 = DB('cat')->where('id',4)->select();
      $si1=DB('news')->field('title,id,pic')->where(['superior_id'=>4])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(15)->select();
      $si2=DB('news')->field('title,id,pic')->where(['superior_id'=>4,'information'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
      $si3=DB('news')->field('title,id,pic')->where(['superior_id'=>4,'information'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
      $si4=DB('news')->field('title,id,pic')->where(['superior_id'=>4,'recommended'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
      $si5=DB('news')->field('title,id,pic')->where(['superior_id'=>4,'recommended'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
        // dump($new1);die;
        $this->assign('type4',$type4);
        $this->assign('cat4',$cat4);
        $this->assign('si1',$si1);
        $this->assign('si2',$si2);
        $this->assign('si3',$san3);
        $this->assign('si4',$si4);
        $this->assign('si5',$si5);
        //第五个
        $type5= DB('cat')->where('parentid',5)->select();
        $cat5 = DB('cat')->where('id',5)->select();
        $wu1=DB('news')->field('title,id,pic')->where(['superior_id'=>5])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(15)->select();
        $wu2=DB('news')->field('title,id,pic')->where(['superior_id'=>5,'information'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
        $wu3=DB('news')->field('title,id,pic')->where(['superior_id'=>5,'information'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
        $wu4=DB('news')->field('title,id,pic')->where(['superior_id'=>5,'recommended'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
        $wu5=DB('news')->field('title,id,pic')->where(['superior_id'=>5,'recommended'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
        $this->assign('type5',$type5);
        $this->assign('cat5',$cat5);
        $this->assign('wu1',$wu1);
        $this->assign('wu2',$wu2);
        $this->assign('wu3',$wu3);
        $this->assign('wu4',$wu4);
        $this->assign('wu5',$wu5);
        //第六个
        $type6= DB('cat')->where('parentid',6)->select();
        $cat6 = DB('cat')->where('id',6)->select();
        $liu1=DB('news')->field('title,id,pic')->where(['superior_id'=>6])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(15)->select();
        $liu2=DB('news')->field('title,id,pic')->where(['superior_id'=>6,'information'=>1,])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
        $liu3=DB('news')->field('title,id,pic')->where(['superior_id'=>6,'information'=>1,])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
        $liu4=Db('news')->field('title,id,pic')->where(['superior_id'=>6,'recommended'=>1,])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
        $liu5=DB('news')->field('title,id,pic')->where(['superior_id'=>6,'recommended'=>1,])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
        $this->assign('type6',$type6);
        $this->assign('cat6',$cat6);
        $this->assign('liu1',$liu1);
        $this->assign('liu2',$liu2);
        $this->assign('liu3',$liu3);
        $this->assign('liu4',$liu4);
        $this->assign('liu5',$liu5);
        //第七个
        $type7= DB('cat')->where('parentid',7)->select();
        $cat7 = DB('cat')->where('id',7)->select();
        $qi1=DB('news')->field('title,id,pic')->where(['superior_id'=>7])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(15)->select();
        $qi2=DB('news')->field('title,id,pic')->where(['superior_id'=>7,'information'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
        $qi3=DB('news')->field('title,id,pic')->where(['superior_id'=>7,'information'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
        $qi4=DB('news')->field('title,id,pic')->where(['superior_id'=>7,'recommended'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
        $qi5=DB('news')->field('title,id,pic')->where(['superior_id'=>7,'recommended'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
        $this->assign('type7',$type7);
        $this->assign('cat7',$cat7);
        $this->assign('qi1',$qi1);
        $this->assign('qi2',$qi2);
        $this->assign('qi3',$qi3);
        $this->assign('qi4',$qi4);
        $this->assign('qi5',$qi5);
        //第八个
        $type8= DB('cat')->where('parentid',8)->select();
        $cat8 = DB('cat')->where('id',8)->select();
        $ba1=DB('news')->field('title,id,pic')->where(['superior_id'=>8])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(15)->select();
        $ba2=DB('news')->field('title,id,pic')->where(['superior_id'=>8,'information'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
        $ba3=DB('news')->field('title,id,pic')->where(['superior_id'=>8,'information'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
        $ba4=DB('news')->field('title,id,pic')->where(['superior_id'=>8,'recommended'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
        $ba5=DB('news')->field('title,id,pic')->where(['superior_id'=>8,'recommended'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
        $this->assign('type8',$type8);
        $this->assign('cat8',$cat8);
        $this->assign('ba1',$ba1);
        $this->assign('ba2',$ba2);
        $this->assign('ba3',$ba3);
        $this->assign('ba4',$ba4);
        $this->assign('ba5',$ba5);
        //第九个
        $type9= DB('cat')->where('parentid',9)->select();
        $cat9 = DB('cat')->where('id',9)->select();
        $jiu1=DB('news')->field('title,id,pic')->where(['superior_id'=>9])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(15)->select();
        $jiu2=DB('news')->field('title,id,pic')->where(['superior_id'=>9,'information'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
        $jiu3=DB('news')->field('title,id,pic')->where(['superior_id'=>9,'information'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
        $jiu4=DB('news')->field('title,id,pic')->where(['superior_id'=>9,'recommended'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
        $jiu5=DB('news')->field('title,id,pic')->where(['superior_id'=>9,'recommended'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
        $this->assign('type9',$type9);
        $this->assign('cat9',$cat9);
        $this->assign('jiu1',$jiu1);
        $this->assign('jiu2',$jiu2);
        $this->assign('jiu3',$jiu3);
        $this->assign('jiu4',$jiu4);
        $this->assign('jiu5',$jiu5);
        //第10个
        $type10= DB('cat')->where('parentid',10)->select();
        $cat10 = DB('cat')->where('id',10)->select();
        $shi1=DB('news')->field('title,id,pic')->where(['superior_id'=>10])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(15)->select();
        $shi2=DB('news')->field('title,id,pic')->where(['superior_id'=>10,'information'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
        $shi3=DB('news')->field('title,id,pic')->where(['superior_id'=>10,'information'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
        $shi4=DB('news')->field('title,id,pic')->where(['superior_id'=>10,'recommended'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
        $shi5=DB('news')->field('title,id,pic')->where(['superior_id'=>10,'recommended'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
        $this->assign('type10',$type10);
        $this->assign('cat10',$cat10);
        $this->assign('shi1',$shi1);
        $this->assign('shi2',$shi2);
        $this->assign('shi3',$shi3);
        $this->assign('shi4',$shi4);
        $this->assign('shi5',$shi5);
        //第11个
        $type11= DB('cat')->where('parentid',11)->select();
        $cat11 = DB('cat')->where('id',11)->select();
        $yan1=DB('news')->field('title,id,pic')->where(['superior_id'=>11])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(15)->select();
        $yan2=DB('news')->field('title,id,pic')->where(['superior_id'=>11,'information'=>1,])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
        $yan3=DB('news')->field('title,id,pic')->where(['superior_id'=>11,'information'=>1,])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
        $yan4=DB('news')->field('title,id,pic')->where(['superior_id'=>11,'recommended'=>1,])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
        $yan5=DB('news')->field('title,id,pic')->where(['superior_id'=>11,'recommended'=>1,])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
        $this->assign('type11',$type11);
        $this->assign('cat11',$cat11);
        $this->assign('yan1',$yan1);
        $this->assign('yan2',$yan2);
        $this->assign('yan3',$yan3);
        $this->assign('yan4',$yan4);
        $this->assign('yan5',$yan5);
        //第12个
        $type12= DB('cat')->where('parentid',12)->select();
        $cat12 = DB('cat')->where('id',12)->select();
        $ju1=DB('news')->field('title,id,pic')->where(['superior_id'=>12])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(15)->select();
        $ju2=DB('news')->field('title,id,pic')->where(['superior_id'=>12,'information'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
        $ju3=DB('news')->field('title,id,pic')->where(['superior_id'=>12,'information'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
        $ju4=DB('news')->field('title,id,pic')->where(['superior_id'=>12,'recommended'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(2)->select();
        $ju5=DB('news')->field('title,id,pic')->where(['superior_id'=>12,'recommended'=>1])->where('areaid','in',[0,'$prefix'])->order('id','desc')->limit(4)->select();
        $this->assign('type12',$type12);
        $this->assign('cat12',$cat12);
        $this->assign('ju1',$ju1);
        $this->assign('ju2',$ju2);
        $this->assign('ju3',$ju3);
        $this->assign('ju4',$ju4);
        $this->assign('ju5',$ju5);
        return $this->fetch();
    }
    //标题数据
    public function title($id,$tid)
    {
        $new = DB('cat')->where('parentid',0)->select();
        $type = DB('cat')->where('id',$tid)->select();
        $hao=DB('news')->where(['superior_id'=>$tid,'recommended'=>1])->limit(10)->order('id','desc')->select();
        $content=DB('news')->where(['id'=>$id,'areaid'=>0])->select();
        foreach ($content as $key => $value) {
            $tent=DB('news_data')->where('news_id',$value['id'])->select();
        }
        // dump($tent);
        $jian=DB('news')->where(['superior_id'=>$tid,'recommended'=>1])->limit(1)->order('id','desc')->select();
        $rong=DB('news')->where(['superior_id'=>$tid,'recommended'=>1])->limit(6)->order('id','desc')->select();
        $re=DB('news')->where(['superior_id'=>$tid,'is_hot'=>1])->limit(1)->order('id','desc')->select();
        $dian=DB('news')->where(['superior_id'=>$tid,'is_hot'=>1])->limit(6)->order('id','desc')->select();
        $zi=DB('news')->where(['superior_id'=>$tid,'information'=>1])->limit(1)->order('id','desc')->select();
        $xun=DB('news')->where(['superior_id'=>$tid,'information'=>1])->limit(6)->order('id','desc')->select();
        // dump($title);
        $this->assign('re',$re);
        $this->assign('dian',$dian);
        $this->assign('zi',$zi);
        $this->assign('xun',$xun);
        $this->assign('rong',$rong);
        $this->assign('jian',$jian);
        $this->assign('new',$new);
        $this->assign('content',$content);
        $this->assign('tent',$tent);
        $this->assign('type',$type);
        $this->assign('hao',$hao);
        return $this->fetch("index/detail");
    }
    //栏目数据
    public function type($id,$rid)
    {
      $new = DB('cat')->where('parentid',0)->select();
      $content=DB('cat')->where('parentid',$id)->select();
      if($rid==0){
          $title = DB('news')->where(['superior_id'=>$id])->paginate(10);
      }else{
          $title = DB('news')->where(['type_id'=>$rid])->paginate(10);
      }
      
      $jian=DB('news')->where(['superior_id'=>$id,'recommended'=>1])->limit(1)->order('id','desc')->select();
      $rong=DB('news')->where(['superior_id'=>$id,'recommended'=>1])->limit(6)->order('id','desc')->select();
      $re=DB('news')->where(['superior_id'=>$id,'is_hot'=>1])->limit(1)->order('id','desc')->select();
      $dian=DB('news')->where(['superior_id'=>$id,'is_hot'=>1])->limit(6)->order('id','desc')->select();
      $zi=DB('news')->where(['superior_id'=>$id,'information'=>1])->limit(1)->order('id','desc')->select();
      $xun=DB('news')->where(['superior_id'=>$id,'information'=>1])->limit(6)->order('id','desc')->select();
      // $list = DB::table('xd_news')->where('superior_id',$id)->paginate(10);
      // dump($title);
      $this->assign('re',$re);
      $this->assign('dian',$dian);
      $this->assign('zi',$zi);
      $this->assign('xun',$xun);
      $this->assign('rong',$rong);
      $this->assign('jian',$jian);
      $this->assign('content',$content);
      $this->assign('title',$title);
      $this->assign('new',$new);
      // $this->assign('list',$list);
      return $this->fetch("index/module");
    }
    //栏目大类遍历小类
    public function classify($tid)
    {
      // return $tid;
      $class = DB('news')->where(['type_id'=>$tid])->limit(10)->select();
      // $this->assign('class',$class);
      // return $this->fetch("index/module");
      return $class;
    }
}
